import React from 'react';
import actionCreators from '../store/actionCreators/counter1';
import {useSelector,useDispatch} from '../react-redux';
function Counter1(){
	console.log('Counter1 render');
	//使用一个选择器，参数是是一个映射函数，把总状态映射出来结果出来
	const {number} = useSelector(state=>state.counter1);
	const dispatch = useDispatch();
	return (
		<div>
			<p>{number}</p>
			<button onClick={()=>dispatch(actionCreators.add1())}>+</button>
			<button onClick={()=>dispatch(actionCreators.minus1())}>-</button>
			<button onClick={()=>dispatch(actionCreators.thunkAdd())}>thunkAdd</button>
			<button onClick={()=>dispatch(actionCreators.promiseAdd())}>promiseAdd</button>
			<button onClick={()=>dispatch(actionCreators.promise2Add()).catch(err=>console.log(err))}>promise2Add</button>
		</div>
	)
}
export default Counter1
